{extend name="../../../view/public/base" /}

{block name="body"}
<div class="bw-container">
    <div class="bw-main">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">

            <!--搜索区域-->
            <div class="layui-card">
                <div class="layui-collapse" lay-accordion="" lay-filter="search">
                    <div class="layui-colla-item">
                        <h2 class="layui-colla-title">查询条件</h2>
                        <div class="layui-colla-content">
                            <form id="searchForm" class="layui-form" lay-filter="searchForm" autocomplete="off">

                                <div class="layui-form-item layui-inline">
                                    <label class="layui-form-label">序号</label>
                                    <div class="layui-input-inline">
                                        <input type="number" name="id" placeholder="请输入序号"
                                               class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-form-item layui-inline">
                                    <label class="layui-form-label">租户ID</label>
                                    <div class="layui-input-inline">
                                        <input type="number" name="member_id" placeholder="请输入租户ID"
                                               class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button class="layui-btn layui-btn-normal" type="button" lay-submit lay-filter="searchBtn">
                                            搜索
                                        </button>
                                        <button class="layui-btn layui-btn-primary" type="button" onclick="resetForm()">
                                            重置
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>

            <!--列表区域-->
            <div class="layui-card" style="background-color: #F2F2F2;">
                <table id="list" lay-filter="listFilter"></table>

                <!--工具栏-->
                <script type="text/html" id="listToolbar">
                    <a class="layui-btn layui-btn-sm layui-bg-black" lay-event="refresh" title="刷新"><i class="layui-icon layui-icon-refresh" style="font-size: 8px !important;"></i> </a>
                    <a class="layui-btn layui-btn-sm layui-btn-danger" lay-event="del" title="删除">删除</a>
                </script>

                <!--租户ID-->
                <script type="text/html" id="member_id">
                    {{ d.member_id }}
                </script>
                <!--资金类型:money=余额,freeze_money=冻结金额-->
                <script type="text/html" id="money_type">
                    {{# if (d.money_type == 'money') { }}
                    <span style="color: #1E9FFF;">余额</span>
                    {{# } else if(d.money_type == 'freeze_money') { }}
                    <span style="color: #1E9FFF;">冻结金额</span>
                    {{# } else { }}
                    <span style="color: #1E9FFF;">{{d.money_type}}</span>
                    {{# } }}
                </script>
                <!--类型:admin=系统,recharge=充值.miniapp=购买应用,cloud_packet=购买云市场套餐-->
                <script type="text/html" id="type">
                    {{# if (d.type == 'admin') { }}
                    <span style="color: #1E9FFF;">系统</span>
                    {{# } else if(d.type == 'recharge') { }}
                    <span style="color: #1E9FFF;">充值</span>
                    {{# } else if(d.type == 'miniapp') { }}
                    <span style="color: #1E9FFF;">购买应用</span>
                    {{# } else if(d.type == 'cloud_packet') { }}
                    <span style="color: #1E9FFF;">购买云市场套餐</span>
                    {{# } else { }}
                    <span style="color: #1E9FFF;">{{d.type}}</span>
                    {{# } }}
                </script>
                <!--变更-->
                <script type="text/html" id="value">
                    {{ d.value }}
                </script>
                <!--变更前-->
                <script type="text/html" id="before">
                    {{ d.before }}
                </script>
                <!--变更后-->
                <script type="text/html" id="after">
                    {{ d.after }}
                </script>
                <!--备注-->
                <script type="text/html" id="memo">
                    {{ d.memo }}
                </script>
                <!--创建时间-->
                <script type="text/html" id="create_time">
                    {{ formatDate(d.create_time) }}
                </script>
                <!--更新时间-->
                <script type="text/html" id="update_time">
                    {{ formatDate(d.update_time) }}
                </script>
                <!--昵称-->
                <script type="text/html" id="Member_mobile">
                    {{ d.Member.mobile }}
                </script>


                <!--状态开关-->
                <script type="text/html" id="listBar">
                    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
                </script>
            </div>
        </div>
    </div>
</div>
</div>

{/block}

{block name="js"}
<script>
    var element, form, table;

    layui.use(['element', 'form', 'table'], function () {
        element = layui.element;
        form = layui.form;
        table = layui.table;
        //用模板渲染的数据渲染form
        bwRenderForm({:json_encode($where)});
        //执行列表
        table.render({
            elem: '#list',
            url: "{:Url('/manage/admin/member/walletBill/index')}",
            where: getWhere(),
            response: {
                statusCode: 200,  //规定成功的状态码，默认：0
            },
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.data.total, //解析数据长度
                    "data": res.data.data.list //解析数据列表
                };
            },
            toolbar: '#listToolbar',
            cols: [[
                {type:'checkbox', fixed: 'left'},
                {field: 'id', title: '序号', align: 'center', width: 80, fixed: 'left'},
                {field: 'member_id', title: '租户ID', align: 'center', width: 80, templet: '#member_id'},
                {field: 'Member_mobile', title: '手机号', align: 'center', minWidth: 120, templet: '#Member_mobile'},
                {field: 'money_type', title: '资金类型', align: 'center', width: 100, templet: '#money_type'},
                {field: 'type', title: '类型', align: 'center', width: 100, templet: '#type'},
                {field: 'value', title: '变更', align: 'center', width: 150, templet: '#value'},
                {field: 'before', title: '变更前', align: 'center', width: 150, templet: '#before'},
                {field: 'after', title: '变更后', align: 'center', width: 150, templet: '#after'},
                {field: 'memo', title: '备注', align: 'center', minWidth: 150, templet: '#memo'},
                {field: 'create_time', title: '创建时间', align: 'center', width: 160, templet: '#create_time'},
                {field: 'update_time', title: '更新时间', align: 'center', width: 160, templet: '#update_time'},

                {title: '操作', toolbar: '#listBar', align: 'center', fixed: "right", width: 140}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true
        });

        //监听表格头部工具栏事件
        table.on('toolbar(listFilter)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'refresh':
                    reload();
                    break;
                case 'del':
                    var checkStatus = table.checkStatus('list');
                    var data = checkStatus.data;

                    var idsArr = [];
                    data.forEach(function(value) {
                        idsArr.push(value.id);
                    });
                    ids = idsArr.join(',');

                    if(!ids) layer.msg('没有选中行', {icon: 2});
                    else del(ids);

                    break;
            }
        });

        //监听工具条
        table.on('tool(listFilter)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）

            switch (layEvent) {
                case 'del':
                    del(obj.data.id);
                    break;
            }
        });

        form.on('submit(searchBtn)', function (data) {
            reload(1);

            return false;
        })


    });
</script>
{/block}